﻿<Window x:Class="Hopscotch.Application.Shell.LoginDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:lgn="clr-namespace:Hopscotch.Application.Shell.Login"
        xmlns:cmnCnvrtrs="clr-namespace:Hopscotch.Presentation.Common.Converters;assembly=Hopscotch.Presentation.Common"

        mc:Ignorable="d"
        Title="Hopscotch"
        Width="380" SizeToContent="Height"
        WindowStyle="ToolWindow" ResizeMode="NoResize"
        x:Name="LoginDialogWindow"
        d:DataContext="{d:DesignInstance Type=lgn:LoginViewModel, IsDesignTimeCreatable=True}">

    <Window.Resources>
        <cmnCnvrtrs:StringToVisibiltyConverter x:Key="StringToVisibiltyConverter"/>
        <cmnCnvrtrs:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <cmnCnvrtrs:BooleanToVisibilityConverter x:Key="InvertedBooleanToVisibilityConverter" InvertInput="True"/>
    </Window.Resources>

    <i:Interaction.Triggers>
        <ei:DataTrigger Binding="{Binding Path=IsClosed}" >
            <ei:DataTrigger.Value>
                <sys:Boolean>true</sys:Boolean>
            </ei:DataTrigger.Value>
            <ei:CallMethodAction TargetObject="{Binding ElementName=LoginDialogWindow}" MethodName="Close"/>
        </ei:DataTrigger>
    </i:Interaction.Triggers>

    <DockPanel>

        <Border x:Name="TopBorder" DockPanel.Dock="Top"
            BorderBrush="Black" BorderThickness="1 1 1 1">
            <DockPanel x:Name="TopDockPanel" LastChildFill="True">
                <Image DockPanel.Dock="Top" Source="Images\hopscotch.jpg" Height="120" Stretch="Fill"></Image>
                <ProgressBar DockPanel.Dock="Top"
                             MinHeight="4"
                             IsIndeterminate="{Binding Path=IsBusy}">
                </ProgressBar>
                <Grid Name="LoginDetailsGrid"
                      Visibility="{Binding Path=IsFatalError, Converter={StaticResource InvertedBooleanToVisibilityConverter}}"
                      DockPanel.Dock="Top"
                      Margin="25,10,25,10" >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" SharedSizeGroup="RowSize"/>
                        <RowDefinition Height="Auto" SharedSizeGroup="RowSize"/>
                        <RowDefinition Height="Auto" SharedSizeGroup="RowSize"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="3*" MinWidth="80"/>
                        <ColumnDefinition Width="4*" MinWidth="100"/>
                    </Grid.ColumnDefinitions>

                    <TextBlock Grid.Row="0" Grid.Column="0" MinWidth="120" Margin="1 1 1 1">User Name:</TextBlock>
                    <TextBox Grid.Row="0" Grid.Column="1"
                             x:Name="UsernameTextBox"
                             IsEnabled="{Binding Path=IsLoginEnabled}"
                             MinWidth="120" Margin="1 1 1 1"/>

                    <TextBlock Grid.Row="1" Grid.Column="0" MinWidth="120" Margin="1 1 1 1">Password:</TextBlock>
                    <PasswordBox Grid.Row="1" Grid.Column="1"
                                 x:Name="PasswordTextBox"
                                 IsEnabled="{Binding Path=IsLoginEnabled}"
                                 MinWidth="120" Margin="1 1 1 1"/>

                    <TextBlock Grid.Row="2" Grid.Column="0" MinWidth="120" Margin="1 1 1 1">Environment:</TextBlock>
                    <ComboBox Grid.Row="2" Grid.Column="1"
                              x:Name="EnvironmentCombobox"
                              ItemsSource="{Binding Path=Environments}"
                              SelectedValue="{Binding Environment, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                              DisplayMemberPath="EnvironmentId"
                              IsSynchronizedWithCurrentItem="True"
                              IsEnabled="{Binding Path=IsLoginEnabled}"
                              MinWidth="120" Margin="1 1 1 1">
                    </ComboBox>
                </Grid>

                <Grid Name="ErrorDetailsGrid"
                      Visibility="{Binding Path=IsFatalError, Converter={StaticResource BooleanToVisibilityConverter}}"
                      DockPanel.Dock="Top"
                      Margin="25,10,25,10" >
                    <Grid.RowDefinitions>
                        <RowDefinition SharedSizeGroup="RowSize"/>
                        <RowDefinition SharedSizeGroup="RowSize"/>
                        <RowDefinition SharedSizeGroup="RowSize"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="3*" MinWidth="80"/>
                        <ColumnDefinition Width="4*" MinWidth="100"/>
                    </Grid.ColumnDefinitions>

                    <Image Grid.Row="0" Grid.Column="0" Grid.RowSpan="3"
                           Source="pack://application:,,,/Hopscotch.Presentation.Common;component/Images/attention48.png" Width="48" Height="48"/>
                    <TextBlock Grid.Row="1" Grid.Column="1"
                               Text="{Binding ErrorMessage}" />
                </Grid>

                <TextBlock
                    DockPanel.Dock="Bottom"
                    Margin="5,5,5,5" MaxHeight="100"
                    Visibility="{Binding Path=IsFatalError, Converter={StaticResource InvertedBooleanToVisibilityConverter}}"
                    Text="{Binding Path=StatusMessage, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"/>
            </DockPanel>
        </Border>

        <Border x:Name="BottomBorder"
                DockPanel.Dock="Bottom"
                BorderBrush="Gray" BorderThickness="0 1 0 0" >
            <DockPanel x:Name="BottomDockPanel" Background="Gainsboro">
                <TextBox
                        DockPanel.Dock="Top"
                        MaxHeight="100" Background="Gainsboro"
                        HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"
                        TextWrapping="Wrap"
                        Visibility="{Binding Path=ErrorDetail, Converter={StaticResource StringToVisibiltyConverter}}"
                        Text="{Binding Path=ErrorDetail, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}">
                </TextBox>
                <Grid DockPanel.Dock="Bottom">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="5"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="5"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="80"/>
                        <ColumnDefinition Width="*" MinWidth="60"/>
                        <ColumnDefinition Width="5"/>
                        <ColumnDefinition Width="*" MinWidth="60"/>
                        <ColumnDefinition Width="10"/>
                    </Grid.ColumnDefinitions>
                    <Button Grid.Row="1" Grid.Column="1"
                            IsEnabled="{Binding Path=IsLoginEnabled}"
                            Visibility="{Binding Path=IsLoginVisible, Converter={StaticResource BooleanToVisibilityConverter}}"
                            Click="Login_OnClick">Login</Button>
                    <Button Grid.Row="1" Grid.Column="3"
                            Click="Cancel_OnClick">
                        <Button.Style>
                            <Style TargetType="Button">
                                <Setter Property="Content" Value="Cancel"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Path=IsFatalError}">
                                        <DataTrigger.Value>
                                            <sys:Boolean>true</sys:Boolean>
                                        </DataTrigger.Value>
                                        <DataTrigger.Setters>
                                            <Setter Property="Content" Value="Close"/>
                                        </DataTrigger.Setters>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Button.Style>

                    </Button>
                </Grid>

            </DockPanel>
        </Border>


    </DockPanel>
</Window>
